package cn.kgc.springcloud.web.service.impl;

import cn.kgc.springcloud.web.client.TagClient;
import cn.kgc.springcloud.web.entity.Clazz;
import cn.kgc.springcloud.web.entity.Tag;
import cn.kgc.springcloud.web.mapper.ClazzMapper;
import cn.kgc.springcloud.web.response.ResponseResult;
import cn.kgc.springcloud.web.service.ClazzService;
import cn.kgc.springcloud.web.vo.ClazzVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author mengshun
 * @description 针对表【t_clazz】的数据库操作Service实现
 * @createDate 2024-07-29 09:57:34
 */
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {

    @Resource
    private TagClient tagClient;

    @Override
    public ResponseResult ClazzList() {

        List<Clazz> clazzes = baseMapper.selectList(null);

        List<ClazzVO> collect = clazzes.stream().map(clazz -> {
            ClazzVO clazzVO = new ClazzVO();
            BeanUtils.copyProperties(clazz, clazzVO);

            Integer tagid = clazz.getTagid();
            Tag tag = tagClient.getOneTag(tagid);
            System.out.println("tag = " + tag);


            clazzVO.setTag(tag);
            return clazzVO;
        }).collect(Collectors.toList());

        return ResponseResult.success().data(collect);
    }
}




